
<script>
	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {
			var str = "this is word"
			// var enStr = this.enCode(str)
			// console.log("xxx", enStr);
			var enStr = this.enCode(str)
			console.log("加密数据：",enStr);
			var deStr =this.deCode(enStr)
			console.log("解密数据", deStr)
		},
		methods: {
			            enCode:function(plaintText){
            				var CryptoJS = require("crypto-js");
            				// Encrypt
            				var sKey = "1111111111111111"
            				sKey = CryptoJS.enc.Utf8.parse(sKey)
            				var ciphertext = CryptoJS.AES.encrypt(plaintText, sKey,{
            					iv: sKey,
            					mode: CryptoJS.mode.CBC, // CBC算法
            					padding: CryptoJS.pad.ZeroPadding, //使用pkcs7 进行padding 后端需要注意
            				}).toString();
            				return ciphertext;
            			},
            			deCode:function(ciphertext){
            				var CryptoJS = require("crypto-js");
            				var sKey = "1111111111111111"
            				sKey = CryptoJS.enc.Utf8.parse(sKey)
            				var des = CryptoJS.AES.decrypt(ciphertext, sKey, {
            				    iv: sKey,
            				    mode: CryptoJS.mode.CBC,
            					padding: CryptoJS.pad.ZeroPadding
            				}).toString(CryptoJS.enc.Utf8);
            				return des
            			}
		}
	}
</script>